package test.tcp.one2many;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ManyServer {
	public static void main(String args[]) {
		ServerSocket server = null;
		try {
			// 启动服务端
			server = new ServerSocket(12345);
			System.out.println("服务器启动："
					+ server.getInetAddress().getHostAddress() + ":"
					+ server.getLocalPort());

			while (true) {
				// 监听客户端
				Socket socket = server.accept();
				System.out.println("客户端连接："
						+ socket.getInetAddress().getHostAddress() + ":"
						+ socket.getPort());

				new ServerThread(socket).start();
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				// 关闭服务端
				server.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
